import Vue from "vue"
import * as dayjs from "dayjs"

Vue.filter('NumberFormat', function (value) {
  if (!value) {
    return '0'
  }
  let intPartFormat = value.toString().replace(/(\d)(?=(?:\d{3})+$)/g, '$1,') //将整数部分逢三一断
  return intPartFormat
})

Vue.filter('dayjs', function (dataStr, pattern = 'YYYY-MM-DD HH:mm:ss') {
  return dayjs(dataStr).format(pattern)
})

Vue.filter('moment', function (dataStr, pattern = 'YYYY-MM-DD HH:mm:ss') {
  return dayjs(dataStr).format(pattern)
})

/** 字符串超长截取省略号显示 */
Vue.filter('ellipsis', function (value, vlength = 25) {
  if (!value) {
    return ""
  }
  console.log('vlength: ' + vlength)
  if (value.length > vlength) {
    return value.slice(0, vlength) + '...'
  }
  return value
})

Vue.filter('numToFixed2', function (value) {
  let val = ''
  if (!isNaN(value) && value != '') {
    if (value % 1 == 0 && value != 0) {//整数
      val = value + ".00"
    }
    else if (value == 0) {
      val = '0.00'
    }
    else {//小数
      val = parseFloat(value).toFixed(2)
    }
  } else {
    val = '0.00'
  }
  return val
})

Vue.filter('timestampToTime', function (timestamp) {
  var date = new Date(Number(timestamp))//时间戳为10位需*1000，时间戳为13位的话不需乘1000
  var Y = date.getFullYear() + '-'
  var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-'
  var D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ' '
  var h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':'
  var m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':'
  var s = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds())
  var strDate = Y + M + D + h + m + s
  return strDate//2020-07-30 01:05:54
})
Vue.filter('timestampToTime1', function (timestamp) {
  var date = new Date(Number(timestamp) * 1000)//时间戳为10位需*1000，时间戳为13位的话不需乘1000
  var Y = date.getFullYear() + '-'
  var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-'
  var D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ' '
  var h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':'
  var m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':'
  var s = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds())
  var strDate = Y + M + D + h + m + s
  return strDate//2020-07-30 01:05:54
})

Vue.filter('applyHand', function (arr) {
  let newArr = arr.filter(function (item) {
    return item.id != 14 && item.id != 15
  })
  console.log(newArr)
  return newArr
})

